package com.yuyou.train.user.service.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yuyou.train.service.api.lesson.entity.LessonClassUserRelation;
import com.yuyou.train.service.api.lesson.service.LessonAPI;
import com.yuyou.train.service.api.user.entity.UserHwTeacher;
import com.yuyou.train.user.mapper.UserHwTeacherMapper;
import com.yuyou.train.user.service.IUserHwTeacherService;
import com.yuyou.train.user.service.IUserService;
import com.yuyou.train.util.bean.ResBoolSimpleInfo;
import com.yuyou.train.util.enums.user.UserEnums;
import com.yuyou.train.util.tool.Sequence;
import com.yuyou.train.util.tool.UUIDUtil;

@Service
public class UserHwTeacherServiceImpl implements IUserHwTeacherService{

	@Autowired
	private UserHwTeacherMapper userHwTeacherMapper;
	
	@Autowired
	private IUserService userService;
	
	@Autowired
	private LessonAPI lessonAPI;
	
	@Override
	public int deleteByPrimaryKey(String id) {
		return userHwTeacherMapper.deleteByPrimaryKey(id);
	}

	@Override
	public int insert(UserHwTeacher record) {
		record.setId(Sequence.getSequence().getNextId());
		record.setCreateTime(new Date());
		return userHwTeacherMapper.insert(record);
	}

	@Override
	public UserHwTeacher selectByPrimaryKey(String id) {
		return userHwTeacherMapper.selectByPrimaryKey(id);
	}

	@Override
	public int updateByPrimaryKeySelective(UserHwTeacher record) {
		return userHwTeacherMapper.updateByPrimaryKeySelective(record);
	}

	@Override
	public ResBoolSimpleInfo<String> addUserHw(UserHwTeacher userHwTeacher) {
		this.insert(userHwTeacher);
		return ResBoolSimpleInfo.getSuccessInfo();
	}

	@Override
	public ResBoolSimpleInfo<String> addTeacherUserHw(String userHwId,String classId) {

		//找出所有老师
		List<LessonClassUserRelation> list=lessonAPI.findLesClsUseRelByClassId(classId,UserEnums.type.teacher.getValue());
		for(LessonClassUserRelation rel:list){
			UserHwTeacher record=new UserHwTeacher();
			record.setStatus("0");
			record.setUserHwId(userHwId);
			record.setUserId(rel.getUserId());
			record.setScore(0);
			this.insert(record);
		}
		return ResBoolSimpleInfo.getSuccessInfo();
	}

	@Override
	public UserHwTeacher selectByHwAndUserId(String userHwId, String userId) {
		return userHwTeacherMapper.selectByHwAndUserId(userHwId, userId);
	}

	@Override
	public List<UserHwTeacher> findByHw(String userHwId, String status) {
		return userHwTeacherMapper.findByHw(userHwId, status);
	}

	@Override
	public ResBoolSimpleInfo<String> addMyTeacherUserHw(String userHwId,
			String teacherId,String status) {
		UserHwTeacher record=new UserHwTeacher();
		record.setStatus(status);
		record.setUserHwId(userHwId);
		record.setUserId(teacherId);
		record.setScore(0);
		this.insert(record);
		return ResBoolSimpleInfo.getSuccessInfo();
	}
	
	
	
	

}